Read OBJ file¶

In [1]:
import py3d
o=py3d.read_obj("Plate.obj", "Plate.jpg")
o
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/.local/lib/python3.8/site-packages/IPython/core/formatters.py:344, in BaseFormatter.__call__(self, obj)
    342     method = get_real_method(obj, self.print_method)
    343     if method is not None:
--> 344         return method()
    345     return None
    346 else:

File ~/work/py3d/py3d/py3d/core.py:544, in OBJ._repr_html_(self)
    542 def _repr_html_(self):
    543     if self.texture:
--> 544         return self.as_mesh()._repr_html_()
    545     elif any(self.vi):
    546         return self.as_wireframe()._repr_html_()

File ~/work/py3d/py3d/py3d/core.py:1589, in Point._repr_html_(self)
   1588 def _repr_html_(self):
-> 1589     return viewer.render(self)._repr_html_()

File ~/work/py3d/py3d/py3d/core.py:212, in Viewer.render(self, obj, t)
    208     self.min = numpy.min(
    209         [self.min, obj.xyz.flatten().min(-2)], axis=0).tolist()
    210 if hasattr(obj, "texture") and obj.texture:
    211     texture = f"data:image/png;base64," + \
--> 212         base64.b64encode(obj.texture).decode("utf-8")
    213 else:
    214     texture = ""

File /usr/lib/python3.8/base64.py:58, in b64encode(s, altchars)
     51 def b64encode(s, altchars=None):
     52     """Encode the bytes-like object s using Base64 and return a bytes object.
     53 
     54     Optional altchars should be a byte string of length 2 which specifies an
     55     alternative alphabet for the '+' and '/' characters.  This allows an
     56     application to e.g. generate url or filesystem safe Base64 strings.
     57     """
---> 58     encoded = binascii.b2a_base64(s, newline=False)
     59     if altchars is not None:
     60         assert len(altchars) == 2, repr(altchars)

TypeError: a bytes-like object is required, not 'str'
Out[1]:
<py3d.core.OBJ at 0x7fdd28dc30d0>

Show vertex

In [2]:
o.as_point(py3d.Color(r=1, g=0.7), pointsize=1)
Out[2]:

Read ply file

In [3]:
import py3d
mesh = py3d.read_ply("cube.ply")
print(mesh.vertices)
print(mesh.faces)
mesh
[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]]
[[0, 1, 2, 3], [7, 6, 5, 4], [0, 4, 5, 1], [1, 5, 6, 2], [2, 6, 7, 3], [3, 7, 4, 0]]
Out[3]:

Convert npy file to ply file

In [4]:
py3d.read_npy("lidar.npy").to_ply("lidar.ply")

Read a ply file

In [5]:
py3d.read_ply("lidar.ply")
Out[5]:
In [ ]: